package com.dingding.web.activity;

import javax.annotation.Resource;

import com.dingding.facde.rentsale.IRentSaleCarService;
import com.dingding.facde.rentsale.dto.ReqPlaceRentSaleOrder;
import com.dingding.facde.rentsale.dto.ResGetRentSaleOrderStatus;
import com.dingding.facde.rentsale.enums.CancelRentSaleOrderEnum;
import com.dingding.facde.rentsale.enums.GetRentSaleOrderEnum;
import com.dingding.facde.rentsale.enums.IsExistOrderEnum;
import com.dingding.facde.rentsale.enums.RentSaleOrderEnum;
import com.dingding.web.base.action.BaseAction;

/**
 * @Description:以租代购活动action
 * @author fengshuonan
 * @date 2016年7月4日 下午5:17:02
 * @version 叮叮搭车
 * @since 2.3.0
 */
@SuppressWarnings("serial")
public class RentSaleCarActiceAction extends BaseAction{
	
	
	@Resource(name = "rentSaleCarService")
	private IRentSaleCarService rentSaleCarService;  //以租代购活动service
	
	
	/**
	 * @Description:以租代购汽车下单
	 * @author fengshuonan
	 * @since 2.3.0
	 */
	public String placeRentSaleOrder(){
		
		String userId = getPara("userId");
		String carId = getPara("carId");
		String cityId = getPara("cityId");
		
		ReqPlaceRentSaleOrder order = new ReqPlaceRentSaleOrder(userId,cityId,carId);
		RentSaleOrderEnum result = this.rentSaleCarService.placeRentSaleOrder(order);
		
		super.writeResponseJsonp(result.getMessage());
		
		return NONE;
	}
	
	/**
	 * @Description:判断是否存在已经下的以租代售订单
	 * @author fengshuonan
	 * @since 2.3.0
	 */
	public String isExistRentSaleOrder(){
		
		String userId = getPara("userId");
		
		IsExistOrderEnum result = this.rentSaleCarService.isExistOrder(userId);
		
		super.writeResponseJsonp(result.getMessage());
		
		return NONE;
	}
	
	/**
	 * @Description:获取以租代售活动预约状态
	 * @author fengshuonan
	 * @since 2.3.2
	 */
	public String getRentSaleOrderStatus(){
		
		String userId = getPara("userId");
		
		ResGetRentSaleOrderStatus result = this.rentSaleCarService.getRentCarOrderStatus(userId);
		
		//没有已经预约的订单
		if(result == null){
			super.writeResponseJsonp(GetRentSaleOrderEnum.HAVE_NO_ORDER.getCode(),
					GetRentSaleOrderEnum.HAVE_NO_ORDER.getMessage());
			
		//存在已经预约的订单
		}else{
			super.writeResponseJsonp(GetRentSaleOrderEnum.HAVE_ORDERED_ORDER.getCode(), 
					GetRentSaleOrderEnum.HAVE_ORDERED_ORDER.getMessage(), result);
		}
		
		return NONE;
	}
	
	/**
	 * @Description: 取消以租代售订单
	 * @author fengshuonan
	 * @since 2.3.0
	 */
	public String cancelRentSaleOrder(){
		
		CancelRentSaleOrderEnum theEnum = this.rentSaleCarService.cancelRentCarOrder(getPara("userId"));
		
		super.writeResponseJsonp(theEnum.getCode(), theEnum.getMessage(), null);
		
		return NONE;
	}
}
